import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  //管理界面
  //物流安排

  //入库管理
  {
    path: '/inbound',
    component: Layout,
    meta: { title: '入库管理', icon: 'shopping'},
    children: [{
      path: 'inbound',
      name: 'inbound',
      component: () => import('@/views/wms/inbound'),
      meta: { title: '采购' }
    },
      {
        path: 'inbound_record',
        name: 'inbound_record',
        component: () => import('@/views/wms/inbound_record'),
        meta: { title: '入库' }
      },
      {
        hidden:true,
        path: 'inbound_act',
        name: 'inbound_act',
        component: () => import('@/views/wms/inbound_act'),
        meta: { title: '实际入库' }
      }
    ]
  },
  //出库管理
  {
    path: '/outbound',
    component: Layout,
    meta: { title: '出库管理', icon: 'guide'},
    children: [{
      path: 'outbound',
      name: 'outbound',
      component: () => import('@/views/wms/outbound'),
      meta: { title: '开票' }
    },
      {
        path: 'invoice_no',
        name: 'invoice_no',
        component: () => import('@/views/wms/invoice_no'),
        meta: { title: '发票号反馈' }
      },
      {
        path: 'outbound_record',
        name: 'outbound_record',
        component: () => import('@/views/wms/outbound_record'),
        meta: { title: '配货' }
      }
    ]
  },
  //批次管理
  {
    path: '/',
    component: Layout,
    redirect: '/patch',
    hidden:true,
    children: [{
      path: 'patch',
      name: 'patch',
      component: () => import('@/views/wms/patch'),
      meta: { title: '批次管理', icon: 'dashboard' }
    }]
  },
  //库位管理
  {
    path: '/',
    component: Layout,
    redirect: '/warehouse',
    children: [{
      path: 'warehouse',
      name: 'warehouse',
      component: () => import('@/views/wms/warehouse'),
      meta: { title: '库位管理', icon: 'lock' }
    },
      ]
  },
  //产品管理
  {
    path: '/goods',
    component: Layout,
    meta: { title: '产品管理', icon: 'list'},
    children: [
    //   {
    //   path: 'stock',
    //   name: 'stock',
    //   component: () => import('@/views/wms/stock'),
    //   meta: { title: '库存管理' }
    // },
      {
      path: 'goods',
      name: 'Goods',
      component: () => import('@/views/wms/goods'),
      meta: { title: '产品列表'}
    }
      ]
  },
  //经销商管理
  {
    path: '/',
    component: Layout,
    redirect: '/agency',
    children: [{
      path: 'agency',
      name: 'agency',
      component: () => import('@/views/wms/agency'),
      meta: { title: '经销商管理', icon: 'user' }
    }]
  },
  {
    path: '/accountant',
    component: Layout,
    meta: { title: '财务模块', icon: 'money'},
    children: [
      {
      path: 'inbound',
      name: 'inbound',
      component: () => import('@/views/wms/inbound'),
      meta: { title: '采购' }
    },
      {
        path: 'check_payment',
        name: 'check_payment',
        component: () => import('@/views/wms/check_payment'),
        meta: { title: '确认收款' }
      },
      {
        path: 'daochu',
        name: 'daochu',
        component: () => import('@/views/wms/daochu'),
        meta: { title: '报表导出' }
      }
    ]
  },




  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
